package fr.upstlse.glre.client.administration.document.libelle.action;

import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.WindowEvent;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.user.client.rpc.AsyncCallback;

import fr.upstlse.glre.client.administration.document.libelle.ModificationLibellePanel;
import fr.upstlse.glre.client.administration.document.libelle.ModificationLibelleWindow;
import fr.upstlse.glre.client.utilitaires.ControlerUtil;
import fr.upstlse.glre.client.vo.depot.LibelleVOGWT;

public class DeleteLibelleAction implements Listener<WindowEvent> {

	private LibelleVOGWT libelleVOGWT;

	public DeleteLibelleAction(LibelleVOGWT pLibelleVOGWT) {
		libelleVOGWT = pLibelleVOGWT;
	}

	public void handleEvent(WindowEvent be) {
		if (be.buttonClicked.getText().equals("Yes")) {
			final MessageBox lWaitMessageBox = MessageBox.wait("Information",
					"Suppresion du libellé ", "suppression en cours...");
			AsyncCallback<Object> lCallback = new AsyncCallback<Object>() {
				public void onFailure(Throwable pCaught) {
					lWaitMessageBox.hide();
					MessageBox.alert("Erreur deleteLibelle", pCaught
							.getMessage(), null);
				}

				public void onSuccess(Object pResult) {
					lWaitMessageBox.hide();
					Info.display("Information", "Libellé supprimé avec succès",
							"");
					ModificationLibelleWindow.closeCurrentWindow();
					ModificationLibellePanel.getInstance()
							.getModificationList().remove(
									ModificationLibellePanel.getInstance()
											.getModificationList()
											.getSelectedItem());
				}
			};
			ControlerUtil.getControlerServiceAsyncInstance().deleteLibelle(
					libelleVOGWT, lCallback);
		}
	}

}
